package com.dengqi.mymodule.activity.chenj;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.readystatesoftware.systembartint.SystemBarTintManager;

import androidx.annotation.Nullable;

/**
 * 沉浸式 3种
 * portrait 竖屏 破缺特
 * landscape 横屏 兰斯克艾泼
 * Created by dell on 2018/6/13
 */

public class ChenJActivity extends BaseActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chenj);
        /**
         * 1.使用第三方改变状态栏颜色
         * 布局需要加上android:fitsSystemWindows="true"和android:clipToPadding="false"用来填充状态栏
         * 也可以用方法2再在布局上加填充再在布局上加上背景颜色
         */
//        initWindow();

        /**
         * 2.沉浸式：状态栏透明 （适用于图片背景)
         * 布局上的填充去掉
         * 坑一：
         * 设置了fitSystemWindows = “true”的时候当edittext弹出了软键盘时toolbar被拉伸的问题
         * 在manifest下给问题activity添加android:windowSoftInputMode = “adjustPan”
         */
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0以上的沉浸式
            //让应用主题内容占用系统状态栏的空间,注意:下面两个参数必须一起使用 stable 牢固的
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            //设置状态栏颜色为透明
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4以上的沉浸式
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        /**
         * 3.完全沉浸式：隐藏状态栏 (适用于横屏视频播放)
         * 布局上的填充去掉
         */
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//        if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            getWindow().getDecorView().setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隐藏nav栏
//                            | View.SYSTEM_UI_FLAG_FULLSCREEN//隐藏状态栏
//                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
//            );
//        }
    }
    private void initWindow() {//初始化窗口属性，让状态栏和导航栏透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            int statusColor = Color.parseColor("#bbbbbb");
            tintManager.setStatusBarTintColor(statusColor);
            tintManager.setStatusBarTintEnabled(true);
        }
    }

    public void onBtn1(View view){
        Configuration newConfig = getResources().getConfiguration();
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            //横屏
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            //竖屏
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }

    public void onBtn2(View view){
        startActivity(new Intent(this, NavActivity.class));
    }

    public void onBtn3(View view){
        startActivity(new Intent(this, ImmersionBarActivity.class));
    }
}
